from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from question.serializers.biao_serializers import *
# from question.paginators import *
from question.models import *
from rest_framework.generics import ListAPIView




class BiaoView0(ListAPIView):
    queryset = Label.objects.all()
    serializer_class = BiaoSerializer




class BiaoView(APIView):
    def get(self,request):
        queryset = Label.objects.all()
        serializer = BiaoSerializer2(queryset,many=True)
        return Response(serializer.data)





class BiaoView2(APIView):
    def get(self, request):
        user = request.user
        queryset = user.labels.all()
        serializer = BiaoSerializer2(instance=queryset, many=True)
        return Response(serializer.data)


class BiaoView13(APIView):
    def put(self, request, id):
        user = User.objects.get(id=request.user.id)
        cc = Label.objects.get(id=id)
        cc.users.add(user)

        return Response({'success': True,
                         'message': 'ok'})


class BiaoView14(APIView):
    def put(self, request, id):
        user = User.objects.get(id=request.user.id)
        cc = Label.objects.get(id=id)
        cc.users.remove(user)

        return Response({'success': True,
                         'message': 'ok'})


class BiaoView15(APIView):
    def get(self, request, id):
        queryset = Label.objects.get(id=id)
        serializer = BiaoSerializer1(queryset)
        return Response(serializer.data)